package cn.edu.sjzc;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class MyTest2 {

	/**
	 * prepareStatement
	 * @param args
	 * cuipanpan
	 * 2013-8-5
	 */
	public static void main(String[] args) {
		Connection conn = null;
		PreparedStatement ps = null;
		ResultSet rs = null;
		String drvStr = "com.mysql.jdbc.Driver";
		String connStr = "jdbc:mysql://127.0.0.1:3306/webshop?user=root&password=123";
		String sql = null ;
		String o_id = null;
				try {
					Class.forName(drvStr);
					conn = DriverManager.getConnection(connStr); 					
					BufferedReader br = new BufferedReader(new InputStreamReader(
							System.in));							
					try {
						while((o_id = br.readLine())!=null){
							sql = "SELECT orders.o_ID,customers.c_ID,customers.c_TrueName,customers.c_Gender,orders.o_SendMode,payments.p_Mode ,orderdetails.d_Number,goods.g_Name,goods.g_Price FROM orders" 
						+ " INNER JOIN customers ON orders.c_ID=customers.c_ID"
									+" INNER JOIN payments ON orders.p_Id=payments.p_Id"
						+" INNER JOIN orderdetails ON orders.o_ID=orderdetails.o_ID"
									+" INNER JOIN goods ON orderdetails.g_ID=goods.g_ID"
						+" WHERE orders.o_ID=?";			
							ps = conn.prepareStatement(sql);
							ps.setString(1,o_id);
							rs = ps.executeQuery();
							while(rs.next()){
								System.out.print(rs.getString(1)+"\t");
								System.out.print(rs.getString(2)+"\t");
								System.out.print(rs.getString(3)+"\t");
								System.out.print(rs.getString(4)+"\t");
								System.out.print(rs.getString(5)+"\t");
								System.out.print(rs.getString(6)+"\t");
								System.out.print(rs.getString(7)+"\t");
								System.out.print(rs.getString(8)+"\t");
								System.out.println(rs.getString(9)+"\t");
							}
						}
					} catch (IOException e) {
						
						e.printStackTrace();
					}
					
					rs.close();
					ps.close();
					conn.close();
				} catch (ClassNotFoundException e) {
					System.out.println(e);
				}catch(SQLException e){
					System.out.println(e);
				}
				
	}

}
